/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {number}
 */
export var sumOfLeftLeaves = function (root) {
  if (!root) return 0
  return (
    (!root.left || root.left.left || root.left.right ? 0 : root.left.val) +
    sumOfLeftLeaves(root.left) +
    sumOfLeftLeaves(root.right)
  )
}
